<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="box"></div>

    <script>
      // 未使用var声明,直接报错
      // console.log('first', first)    Uncaught ReferenceError: first is not defined

      var first;
      // 声明未赋值, 打印为undefined
      console.log("first", first);

      frist1 = "abc";
      var text = "abde";
      // 如果没有使用 var 声明变量也可以， 但是不推荐（事实上会被添加到window对象上）
      console.log("frist1", frist1, window);

      // 函数也会添加到window对象上
      function add(a, b) {
        a = a === undefined ? 0 : a;
        b = b === undefined ? 0 : b;
        return a + b;
      }

      console.log(window.add);
    </script>
  </body>
</html>
